<?php
header('content-type:text/html;charset=utf-8');
set_time_limit(0);
ini_set('memory_limit', '512M');
date_default_timezone_set('PRC');
if(php_sapi_name()!='cli'){
    echo 'No authority';exit();
}
const APP_PATH = __DIR__ . '/..';
$application = new Yaf_Application(APP_PATH . "/conf/app.ini");
$application->bootstrap();

//获取argv参数
$uri = explode('/', $argv[1]);
$count = count($uri);
if(isset($uri[2])){
	list($module,$controller,$action) = $uri;
}elseif($uri[1]){
    array_unshift($uri,'index');
	list($module,$controller,$action) = $uri;
}else{
    [$module,$controller,$action] = ['index', 'Index', 'index'];
}
$argvs = array_slice($argv, 2);
$params = [];
array_walk($argvs, function($agv) use(&$params){
    parse_str($agv, $param);
    $params = array_merge($params, $param);
});
$Request = new Yaf_Request_Simple('CLI', $module, $controller, $action, $params);

//启动
$application->getDispatcher()->dispatch($Request);
